//
//  WBStatus.swift
//  SainMicroblog
//
//  Created by chenxinju on 16/5/6.
//  Copyright © 2016年 chenxinju-a2. All rights reserved.
//

import UIKit

class WBStatus: NSObject {
    
    ///  created_at	string	微博创建时间
    var created_at: String?
    ///id	int64	微博ID
    var id: Int = 0
    ///  idstr	string	字符串型的微博ID
    var idstr: String?
    ///text	string	微博信息内容
    var text: String?
    ///source	string	微博来源
    var source: String?
    
    
    
    ///user	object	微博作者的用户信息字段 详细 -- 这个是对象类型，比较特殊，我们把上边的处理完成之后再处理
    var user: WBStatusUser?
    
//    reposts_count	int	转发数
    var reposts_count: Int = 0
//    comments_count	int	评论数
    var comments_count: Int = 0
//    attitudes_count	int	表态数
    var attitudes_count: Int = 0
//    mlevel	int	暂未支持
    
    //MARK:- 转发微博
    /// retweeted_status	object	转发的微博信息字段
    var retweeted_status: WBStatus?
    
    //转发配图
    var pic_urls: [WBPhotoViewModel]?
    
    

    // 手动的调用一下 赋值
    init(dic: [String: AnyObject]){
     super.init()
    
      setValuesForKeysWithDictionary(dic)
        
       //调用完KVC之后 再手动赋值
        if let userDic = dic["user"] as? [String:AnyObject]{
        
            user = WBStatusUser(dic:userDic)
        }
        
        //遍历转发微博的信息
       if let retweeted_statusDic = dic["retweeted_status"] as? [String:AnyObject] {
          retweeted_status = WBStatus(dic: retweeted_statusDic)
           
        }

    
    //配图的url转模型
    if let pic_URLs = dic["pic_urls"] as? [[String: AnyObject]]{
      
        pic_urls = [WBPhotoViewModel]()
        
        for pic_url in pic_URLs {
          
        let Model = WBPhotoImage(dic: pic_url)
             //加入ViewModel中
            let viewModel = WBPhotoViewModel(model: Model)
            //加入到数组 注意数组要初始化
            pic_urls?.append(viewModel)
        }
    
       }
   
    }



    //实现防止崩溃的方法
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
       }

}
